package tech.anzhen.simple.rpc.support.runtime;

import tech.anzhen.simple.rpc.support.exception.BaseException;

@SuppressWarnings("serial")
public class ModuleException extends BaseException {

    private String errorCode;

    public ModuleException(String errorCode) {
        this(errorCode, null, null);
    }

    public ModuleException(String errorCode, String message) {
        this(errorCode, message, null);
    }

    public ModuleException(String errorCode, Throwable cause) {
        this(errorCode, null, cause);
    }

    public ModuleException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public String getModuleErrorCode() {
        return errorCode;
    }

    public String getModuleCode() {
        return errorCode.substring(0, 4);
    }

    public boolean isCodeEquals(Enum<?> code) {
        return errorCode.equals(ModuleErrorCode.getModuleErrorCode(code));
    }

}
